package practice.hot100;

import java.util.*;

public class Solution763 {
    public List<Integer> partitionLabels(String s) {
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            map.put(s.charAt(i), i);
        }
        List<Integer> res = new ArrayList<>();
        int cover = 0;
        int index = -1;
        for (int i = 0; i < s.length(); i++) {
            cover = Math.max(cover, map.get(s.charAt(i)));
            if (i == cover) {
                res.add(i - index);
                index = i;
            }
        }
        return res;
    }
}
